package com.moss.cloud.plugins.api.contant.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

@Getter
@AllArgsConstructor
public enum TypeMapping {
    VARCHAR("varchar", "String"),
    DECIMAL("decimal", "BigDecimal"),
    INT("int", "Integer"),
    GIG_INT("bigint", "Long"),
    CHAR("char", "char"),
    DATE_TIME("datetime", "LocalDateTime"),
    DATE("date", "LocalDate"),
    TEXT("text", "String"),
    TINYINT("tinyint", "Boolean"),

    ;
    /**
     * 数据类型
     */
    private final String dataType;
    /**
     * java类型
     */
    private final String javaType;


    /**
     * 获得dataType对应的java类型
     *
     * @param dataType
     * @return
     */
    public static String getJavaType(String dataType) {
        Optional<String> javaType = Arrays.stream(TypeMapping.values())
                .filter(mapping -> mapping.getDataType().equals(dataType))
                .map(TypeMapping::getJavaType)
                .findFirst();
        return javaType.orElse(null); // 或者根据需求返回默认值
    }
}
